package textdiff {
	import mx.collections.ArrayCollection;
	

	/**
	 * Delete a block from the old file.
	 */
	public class DeleteCommand extends EditCommand {
		
	    public function DeleteCommand(oldFileInfo:FileInfo=null, newFileInfo:FileInfo=null) {
	        super( oldFileInfo, newFileInfo );
	        command = "Delete";
	        if (oldFileInfo != null) {
		    	oldLines = oldFileInfo.nextBlock();
	        	oldLines.reportable = true;
	        }
	    }

	    public override function toXML():XML {
	    	var result:XML = <command id={command}></command>;
	    	result.appendChild(oldLines.toXML());
	    	return result;
	    }
	    
	    public override function toEditScript(): String {
	    	var s:String = ""+oldLines.fromLineNum;
	    	if (oldLines.fromLineNum < oldLines.thruLineNum) {
	    		s += "," + oldLines.thruLineNum;
	    	} 
	    	s += "d\r.\r";
	    	return s;
	    }
	    
	    public override function editText(t:Array, offset:int=0): Array {
//	    	var lines:ArrayCollection = new ArrayCollection(t.slice());
//	    	for (var i:int = oldLines.fromLineNum; i<=oldLines.thruLineNum; i++) {
//	    		lines.removeItemAt(oldLines.fromLineNum+offset);
//	    	}
//	    	return lines.toArray();
	    	var lines:Array = t.slice();
	    	lines.splice(oldLines.fromLineNum+offset, oldLines.thruLineNum-oldLines.fromLineNum+1);
	    	return lines;
	    }

	    public override function get fromLineNum(): int { return oldLines.fromLineNum; }
	    public override function get thruLineNum(): int { return oldLines.thruLineNum; }
	}
}